<?php 
namespace Material\Controller;
use Admin\Controller\AdminbaseController;
class DatagridadminController extends AdminbaseController{
	
	protected $m;
	
	function _initialize() {
		parent::_initialize();
		$this->m = D('Datagrid');
	}
	
	public function index(){
		
		if(!$_GET['status']){
			$_GET['status'] = 0;
		}
		//$catsLogic = D('AppsCats','Logic');
		//$this->catsoptions = $catsLogic->_get_select_options_by_groupkey($_GET['appid'],'article',$_GET['cid']);

		$this->display();
	}
	
	public function savedata(){
		if(IS_POST){
			$map['id'] = I('post.id');
			$dname = I('post.dname');
			$dvalue = I('post.dvalue');
			$map[$dname] = $dvalue;
			$this->m->save($map);
		}
	}
	
	public function demo(){
		$this->display();
	}
	
	public function savedatabyenter(){
		if(IS_POST){
			$map['id'] = I('post.pk');
			$dname = I('post.name');
			$dvalue = I('post.value');
			$map[$dname] = $dvalue;
			$this->m->save($map);
		}
	}
	
	
	public function del(){
		$id = array_unique((array)I('ids',0));
		if ( empty($id) ) {
			$this->error('请选择要操作的数据!');
		}
		$map = array('id' => array('in', $id));
		$info = $this->m->where($map)->find();
		if($this->m->where($map)->delete()){
			$this->success('删除成功',U('demo'));
		} else {
			$this->error('删除失败！');
		}
	}
	
	public function listorders() {
		$status = parent::_listorders($this->m);
		if ($status) {
			$this->success("排序更新成功！",U('index'));
		} else {
			$this->error("排序更新失败！");
		}
	}
	
	public function changestatus(){
		$data[$this->m->getPk()] = $_REQUEST['id'];
		$data['status'] = $_REQUEST['status'];
		$data['update_time'] = date('Y-m-d H:i:s');
		if($this->m->save($data)){
			$this->success('状态更新成功');
		}else{
			$this->error('状态更新失败');
		}
	}
}
?>